package cn.com.dycc.util;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import cn.com.dycc.sys_manage.menusysmanagement.entity.Menu;


/**
 * 
 * Description: 菜单树状返回工具类
 * Author: linfangan
 * Version: 1.0
 * Create Date Time: 2017年8月21日 上午9:29:18.
 * Update Date Time: 
 * @see
 */
public class MenuTree {
	
	public static Map<String,Object> mapArray = new LinkedHashMap<String, Object>();
	public List<Menu> menuCommon; 
	public List<Object> list = new ArrayList<Object>(); 
	
	public List<Object> menuList(List<Menu> menu){ 
		this.menuCommon = menu;
		for(Menu x : menu){
			Map<String,Object> mapArr = new LinkedHashMap<String, Object>(); 
			if("0".equals(x.getPid())){
				mapArr.put("id",x.getMenu_no());
				mapArr.put("name",x.getMenu_name());
				mapArr.put("program",x.getProgram());
				mapArr.put("open_local",x.getOpen_local());
				mapArr.put("h5_flag",x.getH5_flag());
				mapArr.put("pid",x.getPid());
				mapArr.put("hidden",x.getHidden());
				mapArr.put("order_no",x.getOrder_no());
				mapArr.put("icon",x.getMenu_icon());
				mapArr.put("id_dro",x.getId_dro());
				//递归，调用下面的menuChild
				mapArr.put("children",menuChild(x.getMenu_no()));
				list.add(mapArr);
			}
		}
//		System.out.println(list);
		return list;
	}
	
	 public List<?> menuChild(String menuNo){
		 List<Object> lists = new ArrayList<Object>();
		 for(Menu a:menuCommon){
			 Map<String,Object> childArray = new LinkedHashMap<String, Object>();
			 if(menuNo.equals(a.getPid())){
				 childArray.put("id",a.getMenu_no());
				 childArray.put("name",a.getMenu_name());
				 childArray.put("program",a.getProgram());
				 childArray.put("open_local",a.getOpen_local());
				 childArray.put("h5_flag",a.getH5_flag());
				 childArray.put("pid",a.getPid());
				 childArray.put("hidden",a.getHidden());
				 childArray.put("order_no",a.getOrder_no());
				 childArray.put("icon",a.getMenu_icon());
				 childArray.put("id_dro",a.getId_dro());
				//递归，调用下面的menuChild
				 childArray.put("children",menuChild(a.getMenu_no()));
				 lists.add(childArray);
			 }
		 }
		 return lists;
	 }
}
